{#
This file is part of EC-CUBE

Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.

http://www.ec-cube.co.jp/

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#}
{% extends 'default_frame.twig' %}

{% set menus = ['setting', 'system', 'authority'] %}

{% block title %}システム設定{% endblock %}
{% block sub_title %}権限管理{% endblock %}

{% form_theme form 'Form/bootstrap_3_horizontal_layout.html.twig' %}

{% block javascript %}
<script>
$(function() {

    var $collectionHolder = $('#table-authority');
    var index = $collectionHolder.find('.input-deny-url').length;

    $('.add').click(function() {
        var prototype = $collectionHolder.data('prototype');
        index++;
        var newForm = prototype.replace(/__name__/g, index);
        var $lastRow = $('#table-authority tbody > tr:last')
        $lastRow.after(newForm);
    });

    $(document).on('click', '.delete', function() {
        $(this).parent('td').parent('tr').remove();
        var idx = $collectionHolder.find('.input-deny-url').length;
        if (idx == 0) {
            var prototype = $collectionHolder.data('prototype');
            var newForm = prototype.replace(/__name__/g, idx);
            var $lastRow = $('#table-authority tbody')
            $lastRow.append(newForm);
        }
    });

});
</script>
{% endblock javascript %}

{% block main %}
<div class="row" id="aside_wrap">
    <form name="form1" method="post" action="{{ url('admin_setting_system_authority') }}">
    {{ form_widget(form._token) }}
        <div id="authority_wrap" class="col-md-9">
            <div id="authority_list_box" class="box">
                <div id="authority_list_box__header" class="box-header">
                    <h3 class="box-title">権限設定</h3>
                    <div style="margin-left: 10px;">
                        <p>{{ app.request.baseUrl ~ '/' ~ app.config.admin_route}}以降からのURLを拒否URLに入力してください。</p>
                        <p>拒否URL以降がアクセス拒否されます。(URLは前方一致)</p>
                        <p>例) /setting <span class="text-danger">※「/」を必ず記入してください</span></p>
                    </div>
                </div><!-- /.box-header -->
                <div id="authority_list_box__body" class="box-body">
                    <div id="authority_list" class="table_list form-inlne">
                        <div id="authority_list__body" class="table-responsive">
                            <table id="table-authority" class="table table-striped table-condensed with-border"
                                    data-prototype="{% filter escape %}{{ include('Setting/System/authority_prototype.twig', {'form': form.AuthorityRoles.vars.prototype}) }}{% endfilter %}">
                                <thead>
                                    <tr id="authority_list__header">
                                        <th id="authority_list__header_role" style="width: 210px;">権限</th>
                                        <th id="authority_list__header_deny_url">拒否URL</th>
                                        <th id="authority_list__header_delete_button" style="width: 80px;"></th>
                                    </tr>
                                </thead>
                                <tbody>
                                {% for form in form.AuthorityRoles %}
                                    <tr id="authority_list__item--{{ loop.index }}">
                                        <td id="authority_list__role--{{ loop.index }}">
                                            {{ form_widget(form.Authority, {'attr': {'class': 'input-authority'}}) }}
                                            {{ form_errors(form.Authority) }}
                                        </td>
                                        <td id="authority_list__deny_url--{{ loop.index }}">
                                            {{ form_widget(form.deny_url, {'attr': {'class': 'input-deny-url'}}) }}
                                            {{ form_errors(form.deny_url) }}
                                        </td>
                                        <td id="authority_list__delete_button--{{ loop.index }}" class="text-center">
                                            <button type="button" class="btn btn-default delete">削除</button>
                                        </td>
                                    </tr>
                                {% endfor %}
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <p id="authority_box__add_button">
                        <button type="button" class="btn btn-default add">行追加</button>
                    </p>
                    <div class="extra-form clearfix">
                        {% for f in form.getIterator %}
                            {% if f.vars.name matches '[^plg*]' %}
                                <div class="form-group">
                                    {{ form_label(f) }}
                                    {{ form_widget(f) }}
                                    {{ form_errors(f) }}
                                </div>
                            {% endif %}
                        {% endfor %}
                    </div>
                </div>
            </div>
        </div><!-- /.col -->

        <div class="col-md-3" id="aside_column">
            <div id="common_box" class="col_inner">
                <div id="common_button_box" class="box no-header">
                    <div id="common_button_box__body" class="box-body">
                        <div id="common_button_box__insert_button" class="row text-center">
                            <div class="col-sm-6 col-sm-offset-3 col-md-12 col-md-offset-0">
                                <button class="btn btn-primary btn-block btn-lg" type="submit">登録</button>
                            </div>
                        </div>
                    </div><!-- /.box-body -->
                </div><!-- /.box -->
            </div>
        </div><!-- /.col -->
    </form>
</div>
{% endblock %}
